/**
 * @param {number[]} vals
 * @param {number[][]} edges
 * @param {number} k
 * @return {number}
 */
var maxStarSum = function (vals, edges, k) {
  let max = vals[0]
  let obj = {}
  vals.forEach(item => {
    max = Math.max(max, item)
  })
  edges.forEach(edge => {
    let i = edge[0]
    let j = edge[1]
    if (vals[j] > 0) {
      if (!obj[i]) {
        obj[i] = []
      }
      obj[i].push(vals[j])
    }
    if (vals[i] > 0) {
      if (!obj[j]) {
        obj[j] = []
      }
      obj[j].push(vals[i])
    }
  })
  Object.keys(obj).forEach(key => {
    let sum = getSum(
      obj[key].sort((a, b) => b - a),
      vals[key],
      k
    )
    max = Math.max(sum, max)
  })
  return max
}
var getSum = function (arr, num, k) {
  let res = num
  let len = Math.min(arr.length, k)
  for (let i = 0; i < len; i++) {
    res += arr[i]
  }
  return res
}

let vals = [1, 2, 3, 4, 10, -10, -20]
vals = [-1, 0]
let edges = [
  [0, 1],
  [1, 2],
  [1, 3],
  [3, 4],
  [3, 5],
  [3, 6]
]
edges = []
let k = 2
k = 1
console.log(maxStarSum(vals, edges, k))
